package com.sanyang.lawyer.controller.adm;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sanyang.lawyer.entity.*;
import com.sanyang.lawyer.service.adm.AdmDispatchService;
import com.sanyang.lawyer.service.adm.AdmEspressCompanyService;
import com.sanyang.lawyer.service.adm.AdmEspressService;
import com.sanyang.lawyer.service.adm.AdmRegisterService;
import com.sanyang.lawyer.service.hr.HrEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: lawyer
 * @description: 快速登记Controller层
 * @author: Mr.Wang
 * @create: 2019-10-23 09:27
 **/

@RestController
@RequestMapping("register")
public class AdmRegisterController {

    @Autowired
    private AdmRegisterService register;

    @Autowired
    private AdmEspressCompanyService company;

    @Autowired
    private AdmEspressService espress;

    @Autowired
    private HrEmpService hrEmpService;

    @Autowired
    private AdmDispatchService dispatchService;

    @RequestMapping("listall")
    public List<Adm_Register> listall(){
        List<Adm_Register> list=register.listall();
        return list;
    }

    //快递公司查询全部
    @RequestMapping("company")
    public List<Adm_Espress_Company> companylistall(){
        List<Adm_Espress_Company> list=company.listall();
        return list;
    }
    @RequestMapping("companyfurry")
    public List<Adm_Espress_Company> companfurry(String companyfu){
        List<Adm_Espress_Company> list=company.companfurry(companyfu);
        return list;
    }


    //快递类型查询全部
    @RequestMapping("espress")
    public List<Adm_Espress> espresslistall(){
        List<Adm_Espress> list=espress.listall();
        return list;
    }

    //快递类型查询全部
    @RequestMapping("espressfurry")
    public List<Adm_Espress> espressfurry(String espressfu){
        List<Adm_Espress> list=espress.espressfurry(espressfu);
        return list;
    }

    //快速登记模糊查询
    @RequestMapping("furry")
    public List<Adm_Register> furry(String rname,String mcompany,String mespress,String state,String kdate,String jdate,String judge){
        Map<String,String> map=new HashMap<String,String>();
        if(rname!=null&&rname!=""){
            map.put("rname",rname);
        }
        if(mcompany!="-1"){
            map.put("mcompany",mcompany);
        }
        if(mespress!="-1"){
            map.put("mespress",mespress);
        }
        if(state!="-1"){
            map.put("state",state);
        }
        if(kdate!=null&&kdate!=""&&jdate!=null&&jdate!=""){
           map.put("judge",judge);
           switch (judge){
               case "1":
                   map.put("kdate",kdate);
                   map.put("jdate",jdate);
                   break;
               case "2":
                   map.put("rkdate",kdate);
                   map.put("rjdate",jdate);
                   break;

           }
        }
        List<Adm_Register> list=register.furry(map);
        return list;
    }

    //getbyid
    @RequestMapping("getbyid")
    public Adm_Register getbyid(int id){
        Adm_Register rg=register.getbyid(id);
        return rg;
    }
    //empinfo
    @RequestMapping("empinfo")
     public List<Hr_emp> empinfo(){
        List<Hr_emp> list=hrEmpService.empquery();
        System.out.println(list.toString());
        return list;
    }

    @RequestMapping("empfruyy")   //模糊查询emp
    public List<Hr_emp> empfruyy(String empname){
        List<Hr_emp> list=hrEmpService.empfruyy(empname);
        return list;
    }

    @RequestMapping("companyinsert")    //快递公司添加
    public String companyinsert(@RequestParam("data")String data) throws IOException {
        Adm_Espress_Company adm=new  Adm_Espress_Company();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Espress_Company com=objectMapper.readValue(data,adm.getClass());
        company.insert(com);
        return "1";
    }
    @RequestMapping("companydelete") //删除
    public String companydelete(int id){
        company.delete(id);
        return "1";
    }


    @RequestMapping("espressinsert")    //快件类型添加
    public String espressinsert(@RequestParam("data")String data) throws IOException {
        Adm_Espress adm=new  Adm_Espress();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Espress es=objectMapper.readValue(data,adm.getClass());
        espress.insert(es);
        return "1";
    }
    @RequestMapping("espressdelete") //删除
    public String espressdelete(int id){
        espress.delete(id);
        return "1";
    }

    @RequestMapping("registerupdate")
    public String update(@RequestParam("data")String data) throws IOException {
        Adm_Register adm=new  Adm_Register();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Register es=objectMapper.readValue(data,adm.getClass());
        register.updateSelective(es);
        return "1";
    }

    @RequestMapping("registerinsert")
    public String insert(@RequestParam("data")String data) throws  Exception{
        Adm_Register adm=new  Adm_Register();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Register es=objectMapper.readValue(data,adm.getClass());
        register.registerinsert(es);
        return "1";
    }

    @RequestMapping("dispatch")
    public List<Adm_Dispatch> dispatch(){
        List<Adm_Dispatch> list=dispatchService.dispatchlist();
        return list;
    }

    @RequestMapping("dispatchfurry")
    public List<Adm_Dispatch> dispatchfurry(String dname,String dkdate,String djdate,String dcompany,String despress){
        Map<String,String> map=new HashMap<String, String>();
        if(dname!=""&&dname!=null){
            map.put("dname",dname);
        }
        if(dkdate!=""&&dkdate!=null&&djdate!=null&&djdate!=""){
            map.put("dkdate",dkdate);
            map.put("djdate",djdate);
        }
        if(dcompany!="-1" && dcompany!="" && dcompany!=null){
            map.put("dcompany",dcompany);
        }
        if(despress!="-1" && despress!="" && despress!=null){
            map.put("despress",despress);
        }
        List<Adm_Dispatch> dispatchfurry = dispatchService.dispatchfurry(map);
        return dispatchfurry;
    }

    //发件查询
    @RequestMapping("dispatchgetbyid")
    public Adm_Dispatch sdgetbyid(int id){
        Adm_Dispatch admDispatch=dispatchService.getbyid(id);
        return admDispatch;
    }

    //修改
    @RequestMapping("dispatchupdate")
    public String dispatchupdate(@RequestParam("data")String data) throws IOException {
        Adm_Dispatch adm=new  Adm_Dispatch();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Dispatch es=objectMapper.readValue(data,adm.getClass());
        System.out.println(es.toString());
        dispatchService.dispatchupdate(es);
        return "1";
    }

    @RequestMapping("inn")
    public String inn(@RequestParam("data")String data) throws IOException {
        Adm_Dispatch adm=new  Adm_Dispatch();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Dispatch es=objectMapper.readValue(data,adm.getClass());
        dispatchService.insert(es);
       return "1";
    }

    @RequestMapping("disdelete")
    public String disdelete(int id){
        dispatchService.delete(id);
        return "1";
    }





}
